/*
 * Achieve it All! - Android app to motivate achieving your goals
 * Copyright (C) 2014  Xilconic
 * 
 * This file is part of Achieve it All!.
 *
 * Achieve it All! is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Achieve it All! is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Achieve it All!.  If not, see <http://www.gnu.org/licenses/>
 */
package com.xilconic.achieveitall.persist;

import java.util.Iterator;

/**
 * Set of helper methods when dealing with SQLite manipulation.
 * @author Xilconic
 *
 */
public final class SqliteHelpers {

	/**
	 * Construct the SQL string for creating a new table.
	 * @param tableName Name of the table.
	 * @param columnDefinitions The column definitions.
	 * @return The SQL string.
	 */
	public static String getStringCreateTable(String tableName, Iterable<ColumnTableDefinition> columnDefinitions) {
		StringBuilder builder = new StringBuilder();
		builder.append("CREATE TABLE ");
		builder.append(tableName);
		builder.append("\n(\n");
		
		Iterator<ColumnTableDefinition> itr = columnDefinitions.iterator();
		while(itr.hasNext()){
		    ColumnTableDefinition columnTableDefinition = itr.next();
		    
			builder.append(columnTableDefinition.toString());
			
			// Add comma, unless last entry
			if(itr.hasNext()){
			    builder.append(",");
			}
			builder.append("\n");
		}
		builder.append(");");

		return builder.toString();
	}

}
